package calculators;

import algorithm.AlgorithmParameters;
import herd.Krill;
import utils.Position;
import utils.PositionMath;

import java.util.List;
import java.util.Random;

public class DiffusionCalculator {
    private Random random = new Random(44);
    private PositionMath positionMath = new PositionMath();

    public void calculateDiffusionMotion(List<Krill> herd,AlgorithmParameters parameters){
        for(Krill krill: herd){
            Position randomizedPosition = randomizePosition();
            positionMath.multiplyPositionImplicitly(randomizedPosition,parameters.randomizeDMAX());
            positionMath.multiplyPositionImplicitly(randomizedPosition,calculateIterationRatio(parameters));

            krill.setDiffusionMotion(randomizedPosition);
        }

    }

    private Position randomizePosition(){
        //ranges [-1,1]
        double x = random.nextDouble() * 2.0 - 1.0;
        double y = random.nextDouble() * 2.0 - 1.0;

        return new Position(x,y);
    }

    private double calculateIterationRatio(AlgorithmParameters parameters){
        return 1.0 - parameters.getIterationRatio();
    }
}
